home *** CD-ROM | disk | FTP | other *** search
/ Aminet 50 / Aminet 50 (2002)(GTI - Schatztruhe)[!][Aug 2002].iso / Aminet / text / edit / tecoc-146.lha / exedgt.c < prev    next >
C/C++ Source or Header  |  1991-07-05  |  2KB  |  60 lines

  1. /*****************************************************************************
  2.  
  3.     ExeDgt()
  4.  
  5.     This function handles a digit encountered in a command string.
  6. It converts the digit and any following digits into a binary value using
  7. the current radix,  and pushes the value onto the expression stack.
  8.  
  9. *****************************************************************************/
  10.  
  11. #include "zport.h"        /* define portability identifiers */
  12. #include "tecoc.h"        /* define general identifiers */
  13. #include "defext.h"        /* define external global variables */
  14. #include "deferr.h"        /* define identifiers for error messages */
  15. #include "chmacs.h"        /* define character processing macros */
  16.  
  17. DEFAULT ExeDgt()        /* execute a digit command */
  18. {
  19.     LONG    TmpLng;
  20.  
  21.     DBGFEN(1,"ExeDgt",NULL);
  22.     if ((Radix == 8) && (*CBfPtr > '7')) {    /* if bad octal digit */
  23.         ErrMsg(ERR_ILN);        /* ILN = "illegal number" */
  24.         DBGFEX(1,DbgFNm,"FAILURE, bad octal digit");
  25.         return FAILURE;
  26.     }
  27.  
  28.     TmpLng = 0;
  29.     do {
  30.         TmpLng *= Radix;
  31.         if (Is_Digit(*CBfPtr)) {
  32.             TmpLng += *CBfPtr - '0';
  33.         } else if (Is_Upper(*CBfPtr)) {
  34.             TmpLng += *CBfPtr - '\67';
  35.         } else {
  36.             TmpLng += *CBfPtr - '\127';
  37.         }
  38.         if (CBfPtr == CStEnd) {
  39. #if DEBUGGING
  40.             sprintf(DbgSBf,"PushEx(%ld,OPERAND)", TmpLng);
  41.             DbgFEx(1,DbgFNm,DbgSBf);
  42. #endif
  43.             return PushEx(TmpLng, OPERAND);
  44.         }
  45.         ++CBfPtr;
  46.         if (IsRadx(*CBfPtr) && TraceM) {
  47.             EchoIt(*CBfPtr);
  48.         }
  49.     } while (IsRadx(*CBfPtr));
  50.  
  51.     --CBfPtr;            /* cancel ExeCSt's ++CBfPtr */
  52.  
  53. #if DEBUGGING
  54.     sprintf(DbgSBf,"PushEx(%ld,OPERAND)", TmpLng);
  55.     DbgFEx(1,DbgFNm,DbgSBf);
  56. #endif
  57.  
  58.     return PushEx(TmpLng, OPERAND);
  59. }
  60.